package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.mapper.StrategyCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StrategyCommentServiceImpl implements IStrategyCommentService {

    @Autowired
    private StrategyCommentMapper commentMapper;

    public PageInfo<?> query(QueryObject qo) {
        qo.setOrderBy("sc.createTime desc");
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<StrategyComment> list = commentMapper.queryForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void updateState(StrategyComment comment) {
        commentMapper.updateByPrimaryKey(comment);
    }

    public List<StrategyComment> selelctStrategyByState() {
        return commentMapper.selelctStrategyByState(StrategyComment.TYPE_RECOMMEND);
    }

    @Override
    public void save(StrategyComment strategyComment) {
        strategyComment.setCreateTime(new Date());
        commentMapper.insert(strategyComment);
    }

    @Override
    public List<StrategyComment> selectByStrategyId(Long strategyId) {

        return commentMapper.selectByStrategyId(strategyId);
    }

    public List<StrategyComment> listByStrategyId(Long id) {
        return commentMapper.listByStrategyId(id);
    }

    public StrategyComment getById(Long id) {
        if (id != null) {
            StrategyComment comment = commentMapper.selectByPrimaryKey(id);
            return comment;
        }
        return null;
    }

    public List<StrategyComment> getCommentByUserId(Long userId) {
        return commentMapper.getCommentByUserId(userId);

    }
    public PageInfo<StrategyComment> queryForLists(StrategyCommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<StrategyComment> list = commentMapper.queryForList(qo);
        return new PageInfo<StrategyComment>(list);
    }

    public PageInfo getStrategyCommentById(StrategyCommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo( commentMapper.selectByUserId(qo));
    }
    @Override
    public StrategyComment selectBystrategyCommentId(Long id) {

        return commentMapper.selectBystrategyCommentId(id);
    }

    @Override
    public List<StrategyComment> selectByUserId(Long userId) {
        return commentMapper.selectByUserId(userId);
    }


}
